﻿using System;

namespace Ndns.ServerHost.Abstractions.Services
{

    public enum LogLevel
    {
        None = 0,
        Trace = 1,
        Debug = 2,
        Info = 4,
        Warning = 8,
        Error = 16,
        Fatal = 32,
    }

    public interface ILogger
    {
        void Log(string traceIdentifier, LogLevel level, string message, Exception exception);

    }

    public static class LoggerExtensions
    {

        public static void LogTrace(this ILogger logger, string traceIdentifier, string message)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            logger.Log(traceIdentifier, LogLevel.Trace, message, null);
        }
        
        public static void LogDebug(this ILogger logger, string traceIdentifier, string message)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            logger.Log(traceIdentifier, LogLevel.Debug, message, null);
        }

        public static void LogInfo(this ILogger logger, string traceIdentifier, string message)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            logger.Log(traceIdentifier, LogLevel.Info, message, null);
        }

        public static void LogWarning(this ILogger logger, string traceIdentifier, string message)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            logger.Log(traceIdentifier, LogLevel.Warning, message, null);
        }

        public static void LogError(this ILogger logger, string traceIdentifier, string message)
        {
            logger.LogError(traceIdentifier, message, null);
        }
        public static void LogError(this ILogger logger, string traceIdentifier, string message, Exception exception)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            logger.Log(traceIdentifier, LogLevel.Error, message, exception);
        }

        public static void LogFatal(this ILogger logger, string traceIdentifier, string message)
        {
            logger.LogFatal(traceIdentifier, message, null);
        }
        public static void LogFatal(this ILogger logger, string traceIdentifier, string message, Exception exception)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            logger.Log(traceIdentifier, LogLevel.Fatal, message, exception);
        }
    }
}
